package com.css.fxfzysx.modules.vaAnalysis.service.impl;

import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.modules.cztDataMange.vo.QueryBacInformationVo;
import com.css.fxfzysx.modules.vaAnalysis.repository.CsVulnerabilityRepository;
import com.css.fxfzysx.modules.vaAnalysis.service.CsVulnerabilityService;
import com.css.fxfzysx.modules.vaolEngineering.entity.MtolProjectEntity;
import com.css.fxfzysx.modules.vaomeFacilities.entity.CipvMatrixEntity;
import com.css.fxfzysx.util.CreateGson;
import com.css.fxfzysx.util.PlatformObjectUtils;
import com.css.fxfzysx.web.PlatformSessionContext;
import com.css.fxfzysx.zcpt.sys.entity.SUser;
import com.css.fxfzysx.zcpt.sys.service.SUserService;
import com.css.fxfzysx.zcpt.sys.service.SysAreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class CsVulnerabilityServiceImpl implements CsVulnerabilityService {

    @Autowired
    private CsVulnerabilityRepository csVulnerabilityRepository;

    @Autowired
    private SUserService userService;

    @Autowired
    private SysAreaService areaService;


    @Override
    public RestResponse buildingCsVulnerability(QueryBacInformationVo queryBacInformationVo) {
        try {
            if(PlatformObjectUtils.isEmpty(queryBacInformationVo.getProvince())){
                String user = userService.getSUser(PlatformSessionContext.getUserID());
                SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
                String province = areaService.getAreaNameByAreaId(sUser.getProvinceId());
                queryBacInformationVo.setProvince(province);
            }
            return RestResponse.succeed(csVulnerabilityRepository.buildingCsVulnerability(queryBacInformationVo));
        } catch (NumberFormatException e) {
            String message = "查看失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public RestResponse lifelineCsVulnerability(MtolProjectEntity mtolProjectEntity) {
        try {
            return RestResponse.succeed(csVulnerabilityRepository.lifelineCsVulnerability(mtolProjectEntity));
        } catch (NumberFormatException e) {
            String message = "查看失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public RestResponse MajorProjectsCsVulnerability(CipvMatrixEntity cipvMatrixEntity) {
        try {
            return RestResponse.succeed(csVulnerabilityRepository.MajorProjectsCsVulnerability(cipvMatrixEntity));
        } catch (NumberFormatException e) {
            String message = "查看失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }
}
